package helper

import (
	"github.com/gookit/color"
	srv "seven-admin/app/admin/service/system"
	"seven-admin/app/collection/system"
	"seven-admin/core"
)

func roleAuth() {
	var roles []system.AuthRole
	roleSrv := srv.NewAuthPermService(core.GetDB())
	core.GetDB().Model(&system.AuthRole{}).Find(&roles)
	if len(roles) == 0 {
		color.Redln("角色表无数据")
		return
	}
	for _, role := range roles {
		err := roleSrv.CacheRoleMenusByRoleId(role.ID)
		if err != nil {
			color.Redln(err)
			return
		}
	}
}

func tenantAuth() {
	var tenants []system.AuthTenant
	tenantSrv := srv.NewAuthTenantPermService(core.GetDB())
	core.GetDB().Model(&system.AuthTenant{}).Where("is_stop = ? and id != ?", 0, 1).Find(&tenants)
	if len(tenants) == 0 {
		color.Redln("租户表无数据")
		return
	}
	for _, tenant := range tenants {
		err := tenantSrv.CacheTenantMenusByTenantId(tenant.ID)
		if err != nil {
			color.Redln(err)
			return
		}
	}
}
